/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufc.quixada.adrs.comandos.admin;

import br.ufc.quixada.adrs.interfaces.Comando;
import br.ufc.quixada.adrs.model.Adrs;
import br.ufc.quixada.adrs.service.AdrsService;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author ismaily
 */
public class CmdBuscaAdrs implements Comando {

    public String executa(HttpServletRequest request, HttpServletResponse response) {
        HttpSession session = request.getSession();
        String nome = request.getParameter("busca");
        session.removeAttribute("listAdrs");
        if (nome == null || nome.trim().equals("")) {
            session.setAttribute("listAdrs", new AdrsService().getAllAdrs());
        } else {
            AdrsService as = new AdrsService();
            List<Adrs> listAdrs = as.searchAdrsByNome(nome);
            if (listAdrs == null || listAdrs.isEmpty()) {
                session.setAttribute("erro", "Nenhum ADRS encontrado.");
            } else {
                session.setAttribute("listAdrs", listAdrs);
            }
        }
        return "/admin/admin_monta_relatorio_qt_passo_dois.jsp";
    }
}
